﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Adultorama.Model;
using System.Data.SqlClient;


namespace Adultorama.Ctrl
{
    class BookingControler
    {
        SqlConnection sql;
        public BookingControler() 
        {
            sql = new SqlConnection(Connection.Default.ConnectionString);
        }

        // Returns the list of available shows
        public List<Show> getShows() 
        {
            List<Show> showList = getShowList();
            
            return showList;
        }

        // List from DB with show info
        List<Show> getShowList()
        {
            try
            {
                sql.Open();

                SqlCommand com = new SqlCommand("Select * From ShowV", sql);
                SqlDataReader read = com.ExecuteReader();
                List<Show> showList = new List<Show>();

                while (read.Read())
                {
                    Show s = new Show();
                    s.showId = Convert.ToInt32(read[0].ToString());
                    //s.date = Convert.ToDateTime(read[1].ToString());
                    //s.startTime = Convert.ToDecimal(read[2].ToString());
                    //s.endTime = Convert.ToDecimal(read[3].ToString());
                    //s.price = Convert.ToInt32(read[4].ToString());
                    s.movie.title = read[5].ToString();
                    //s.theater.id = Convert.ToInt32(read[6].ToString());
                    showList.Add(s);
                }
                return showList;

            }
            catch { return null; }
            finally
            {

                sql.Close();
            }

        }

        public List<Ticket> getBookings() 
        {
            List<Ticket> ticketList = getTicketList();
            return ticketList;
        }

        // Listt from DB with ticket info
        private List<Ticket> getTicketList()
        {
            try
            {
                sql.Open();
                List<Ticket> ticketList = new List<Ticket>();
                SqlCommand com = new SqlCommand("Select * From TicketV", sql);
                SqlDataReader read = com.ExecuteReader();
                List<Show> showList = new List<Show>();

                while (read.Read())
                {
                    Ticket t = new Ticket();
                    t.id = Convert.ToInt32(read[0].ToString());
                    t.phoneNumber = Convert.ToInt32(read[1].ToString());
                    t.status = Convert.ToInt32(read[2].ToString());
                    //t.SeatId = Convert.ToInt32(read[3].ToString());
                    t.showId = Convert.ToInt32(read[5].ToString());
                    ticketList.Add(t);
                }

                return ticketList;
            }
            catch { return null; }
            finally
            {
                sql.Close();
            }
        }

        ////Generates DUMMY DATA DELETE WHEN Db IS RUNNING
        //List<Show> getDummyList()
        //{
        //    //List<Show> showList = new List<Show>();
        //    //Show s = new Show();
        //    //s.showId = 1;
        //    //s.movie.title = "Lesbian Love";
        //    //showList.Add(s);
        //    //Show s2 = new Show();
        //    //s2.showId = 2;
        //    //s2.movie.title = "Lesbian Love 2";
        //    //showList.Add(s2);

        //    return showList;
        //}
        //Returns the list of bookings
        //private List<Ticket> generateDummyTickets() {
        //    List<Ticket> ticketList = new List<Ticket>();
        //    Ticket t1 = new Ticket();
        //    t1.id = 1;
        //    t1.phoneNumber = 29935824;
        //    t1.showId = 1;
        //    ticketList.Add(t1);
        //    Ticket t2 = new Ticket();
        //    t2.id = 2;
        //    t2.phoneNumber = 28514863;
        //    t2.showId = 2;
        //    ticketList.Add(t2);
        //    return ticketList;
        //}
    }
}
